using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{
  public partial class Extender : ElectricalSymbol
  {
		private int _extenderWidth = 1;
		private SymbolOrientation _orientation = SymbolOrientation.Horizontal;
		private ConnectHands _connectHand = ConnectHands.None;
    private bool _crossLine = false;
    private float _curveRatio = .1f;

    public Extender()
    {
      InitializeComponent();
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Length of the Incomer" )]
    public bool CrossLine
    {
      get { return this._crossLine; }
      set
      {
        this._crossLine = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the curve ratio for the cross line" )]
    public float CurveRatio
    {
      get { return this._curveRatio; }
      set
      {
        this._curveRatio = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Width of the Line" )]
		public int ExtenderWidth
    {
			get { return this._extenderWidth; }
      set
      {
        if ( value <= 0 ) return;
				this._extenderWidth = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Orientation of the Line" )]
		public SymbolOrientation Orientation
    {
      get { return this._orientation; }
      set
      {
        this._orientation = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Connector of the Line" )]
    public ConnectHands ConnectHand
    {
      get { return this._connectHand; }
      set
      {
				this._connectHand = value;
        this.Refresh();
      }
    }

    protected override void OnPaint( PaintEventArgs e )
    {
      base.OnPaint( e );
      this.Paint( e );
    }

    protected override void OnResize( EventArgs e )
    {
      base.OnResize( e );
      this.Refresh();
    }

    private new void Paint( PaintEventArgs pea )
    {
      int _lx1 = 0, _ly1 = 0, _lx2 = 0, _ly2 = 0;
      int _lheight = 0, _lwidth = 0;
      int _lgap = 0;

			_lgap = ( int ) Math.Ceiling( this.SymbolSize * this._curveRatio );

      if ( this._orientation == SymbolOrientation.Horizontal )
      {
        _lx1 = 0;
        _ly1 = 0;
				_lx2 = this.SymbolSize;
        _ly2 = 0;
				_lwidth = this.SymbolSize;
				_lheight = this._extenderWidth;
				this.Width = ( this.SymbolSize );
				this.Height = this._extenderWidth;
      }
      else
      {
        _lx1 = 0;
        _ly1 = 0;
        _lx2 = 0;
				_ly2 = this.SymbolSize;
				_lwidth = this._extenderWidth;
				_lheight = this.SymbolSize;
				this.Width = ( this._extenderWidth );
				this.Height = this.SymbolSize;
      }
			
      System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();

			if ( this._extenderWidth <= 1 )
        _gpath.AddLine( _lx1, _ly1, _lx2, _ly2 );
      else
      {
        _gpath.AddRectangle( new Rectangle( _lx1, _ly1, _lwidth, _lheight ) );
      }
      pea.Graphics.FillPath( this.Brush, _gpath );
      pea.Graphics.DrawPath( this.Pen, _gpath );

    }
  }
}